import {
  mapGetters
} from 'vuex'
export default {
  computed: {
    ...mapGetters('m_cart', ['total'])
  },
  onShow() {
    this.setBadge()
  },
  watch: {
    //  监听 total 值的变化，通过第一个形参得到变化后的新值
    total: {
      handler(newval) {
        this.setBadge()
      }
    }
  },
  methods: {
    // 设置徽标
    setBadge() {
      uni.setTabBarBadge({
        index: 2,
        text: this.total + ''
      })
    }
  }
}
